package moxl.xpath.parser.states.step;

import java.util.HashMap;
import java.util.Map;

import moxl.dom.MoxlNode;
import moxl.xpath.parser.types.NodeTestMatcher;

public class NodeTypeMatcher implements NodeTestMatcher
{
	private final static Map<String, NodeTestMatcher> delegates = new HashMap<String, NodeTestMatcher>();

	static
	{
		delegates.put("comment", new CommentNodeTestMatcher());
		delegates.put("text", new TextNodeTestMatcher());
		delegates.put("processing-instruction", new ProcessingInstructionNodeTestMatcher());
		delegates.put("node", new IdentityNodeTestMatcher());
	}

	private final NodeTestMatcher delegate;

	public NodeTypeMatcher(String image)
	{
		this.delegate = delegates.get(image);
		if (delegate == null)
		{
			throw new IllegalStateException("Unrecognized node type: " + image);
		}
	}

	public boolean matches(MoxlNode node)
	{
		return delegate.matches(node);
	}

	public NodeTestMatcher getDelegate()
    {
	    return delegate;
    }

}
